function Enemy(x,y,direct,color) {
	this.x = x;
	this.y = y;
	this.direct = direct;

	this.color = [color,color,color,color];
}
Enemy.prototype = new Tank();
Enemy.prototype.fire = function() {
	if ( !this.isShot ){
		this.isShot = !this.isShot;
		if ( this.direct === 0 ){
			this.bullet = new Bullet( this.x + 15 ,this.y ,this.direct );
			this.bullet.speed = 2 * (this.speed+1);
		}
		if ( this.direct === 1 ){
			this.bullet = new Bullet( this.x + 30 ,this.y + 15 ,this.direct );
			this.bullet.speed = 2 * (this.speed+1);
		}
		if ( this.direct === 2){
			this.bullet = new Bullet( this.x + 15 ,this.y + 30 ,this.direct );
			this.bullet.speed = 2 * (this.speed+1);
		}
		if ( this.direct === 3){
			this.bullet = new Bullet( this.x      ,this.y + 15 ,this.direct );
			this.bullet.speed = 2 * (this.speed+1);
		}
		this.shotInterval = setInterval(bulletRun, 30);
		var _this = this;
		function bulletRun () {
			
			switch ( _this.bullet.direct ){
				case 0: 
					_this.bullet.y -= _this.bullet.speed;
				break;
				case 1: 
					_this.bullet.x += _this.bullet.speed;
				break;
				case 2: 
					_this.bullet.y += _this.bullet.speed;
				break;
				case 3: 
					_this.bullet.x -= _this.bullet.speed;
				break;
			}
			// 被敌方坦克子弹击中
			// 减掉生命值，重置坦克位置
			if( pz( hero , _this.bullet ) ){
				// enemies.splice(i, 1);
				_this.bullet = null;
				clearInterval(_this.shotInterval)
				_this.isShot = !_this.isShot;

				// 英雄减血，重置位置
				hero.life--;
				hero.reset();
				if(hero.life === 0){
					alert('game over');
					clearInterval(flashInterval);
				}
				console.log('击中 Hero !')
				return;
			}
			// 打中边界，销毁子弹，重置坦克子弹
			if ( _this.bullet.x < 0 || _this.bullet.x > 500 ||
					 _this.bullet.y < 0 || _this.bullet.y > 500){
				clearInterval(_this.shotInterval);
				_this.bullet = null;
				_this.isShot = !_this.isShot;
			}
			
			if( _this.bullet )
			{
				// 打中墙壁 
				// 销毁子弹
				// 销毁墙壁
				for (var i = 0 ; i < bricks.length; i++) {
					if ( checkPZ( _this.bullet , bricks[i] ) ){
						bricks.splice(i , 1);
						clearInterval(_this.shotInterval);
						console.log( '敌机击中墙壁' )
						_this.bullet = null;
						_this.isShot = !_this.isShot;
						break;
					}
				}
				// 打中钢板
				// 只销毁子弹
				for (var i = 0 ; i < steels.length; i++) {
					if ( _this.bullet && checkPZ( _this.bullet , steels[i] ) ){
						// steels.splice(i , 1);
						clearInterval(_this.shotInterval);
						_this.bullet = null;
						_this.isShot = !_this.isShot;
						break;
					}
				}
			}
		};
	}
};
/**
 * 设计各种敌军坦克
 */

var easyColor  = [
	[ '#FFFFCC' ,'#CCFFFF' ]
];
var normalColor= [
	[ '#99CC33' ,'#FF9900' ],
	[ '#FF9900' ,'#ffff00' ]
]
var hardColor  = [
	[ '#1F1F20' ,'#2B4C7E' ],
	[ '#2B4C7E' , '#567EBB'],
	[ '#567EBB' , '#606D80'],
	[ '#606D80' , '#DCE0E6']
]
var fastColor  = [
	[ '#E6E365' ,'#FFFC66' ]
];
function EasyEnemy( x , y ,direct ){
	this.x = x || 225;
	this.y = y || 0;
	this.direct = direct || 0;

	this.speed = 1 ;
	this.life  = 1 ;
	this.color = easyColor;
}
EasyEnemy.prototype = new Enemy( 220, 0, 0 );

function NormalEnemy( x , y ,direct ){
	this.x = x || 0;
	this.y = y || 0;
	this.direct = direct || 0;

	this.speed = 1;
	this.life  = 2;
	this.color = normalColor;
}
NormalEnemy.prototype = new Enemy(0 , 0 , 2 );

function HardEnemy( x , y ,direct ){
	this.x = x || 470;
	this.y = y || 0;
	this.direct = direct || 0;

	this.speed = 0.5;
	this.life  = 4;
	this.color = hardColor;
}
HardEnemy.prototype = new Enemy(470 , 0 , 2 );

function FastEnemy( x , y ,direct ) {
	this.x = x || 470;
	this.y = y || 0;
	this.direct = direct || 0;

	this.speed = 2;
	this.life  = 1;
	this.color = fastColor;
}
FastEnemy.prototype = new Enemy(470 , 0 , 2 );
